
package com.hlkj.pay.app.merchant.ext.impl.kuaiqian;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import com.fasterxml.jackson.core.type.TypeReference;
import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.extension.annotation.Extension;
import com.hlkj.pay.app.merchant.ext.ChannelMerchantPaymentExtPt;
import com.hlkj.pay.app.merchant.ext.MerchantExtConstant;
import com.hlkj.pay.app.merchant.ext.dto.payment.ChannelPaymentAccountContext;
import com.hlkj.pay.app.merchant.ext.dto.payment.ChannelPaymentCallBackContext;
import com.hlkj.pay.app.merchant.ext.dto.payment.ChannelPaymentCallBackDto;
import com.hlkj.pay.app.merchant.ext.dto.payment.ChannelPaymentContext;
import com.hlkj.pay.app.merchant.ext.impl.kuaiqian.dto.*;
import com.hlkj.pay.app.merchant.ext.impl.kuaiqian.util.BuildHttpsClient;
import com.hlkj.pay.dto.merchant.MerchantAcctBalanceDto;
import com.hlkj.pay.enums.CommonEnum;
import com.hlkj.pay.enums.MerchantEnum;
import com.hlkj.pay.infrastructure.model.merchant.MerchantAppChannelDO;
import com.hlkj.pay.infrastructure.model.pay.PayChannelRequestDO;
import com.hlkj.pay.infrastructure.model.pay.ProviderChannelConfigDO;
import com.hlkj.pay.infrastructure.model.payment.MerchantPaymentDO;
import com.hlkj.pay.infrastructure.model.payment.MerchantPaymentDetailDO;
import com.hlkj.pay.util.DateUtils;
import com.hlkj.pay.util.HttpRequestUtil;
import com.hlkj.pay.util.MerchantUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author HlpayTeam
 * @date 2024/11/20 17:19
 */
@Slf4j
@Repository
@RequiredArgsConstructor
@Extension(bizId = MerchantExtConstant.CHANNEL_KUAI_QIAN)
public class KuaiQianPaymentExtPt implements ChannelMerchantPaymentExtPt {

    private final BuildHttpsClient buildHttpsClient;

    @Value("${spring.profiles.active}")
    private String active;

    @Override
    public void submitChannelSinglePayment(ChannelPaymentContext channelPayOrderContext) {
        log.info("快钱提交单笔代付 detailPaymentId:{}", channelPayOrderContext.getMerchantPaymentDetailDO().getDetailPaymentId());
        MerchantAppChannelDO merchantAppChannelDO = channelPayOrderContext.getMerchantAppChannelDO();
        MerchantPaymentDO merchantPaymentDO = channelPayOrderContext.getMerchantPaymentDO();
        MerchantPaymentDetailDO merchantPaymentDetailDO = channelPayOrderContext.getMerchantPaymentDetailDO();
        String appConfigJson = merchantAppChannelDO.getAppConfigJson();
        if (!StringUtils.hasText(appConfigJson)) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数未配置");
            return;
        }
        Bill99AppChannelParams bill99AppChannelParams = null;
        try {
            bill99AppChannelParams = JsonUtils.parseObject(appConfigJson, Bill99AppChannelParams.class);
            bill99AppChannelParams(bill99AppChannelParams);
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数配置格式错误");
            return;
        }

        Bill99Header bill99Header = new Bill99Header();
        bill99Header.setMessageType("C1017");
        bill99Header.setMemberCode(bill99AppChannelParams.getMemberCode());
        bill99Header.setExternalRefNumber(merchantPaymentDetailDO.getDetailPaymentId());
        Bill99SinglePaymentDto bill99SinglePaymentDto = buildPaymentDto(merchantPaymentDetailDO, channelPayOrderContext.getNotifyUrl());
        String url = url(channelPayOrderContext.isTest());
        try {
            PayChannelRequestDO payChannelRequestDO = new PayChannelRequestDO();
            payChannelRequestDO.setSn(merchantPaymentDO.getSn());
            payChannelRequestDO.setProviderCode(merchantPaymentDO.getProviderCode());
            payChannelRequestDO.setChannelCode(merchantPaymentDO.getChannelCode());
            payChannelRequestDO.setMchChannelCode(merchantPaymentDO.getMchChannelCode());
            payChannelRequestDO.setRelationId(merchantPaymentDetailDO.getDetailPaymentId());
            // payChannelRequestDO.setRequestId();
            // payChannelRequestDO.setRuzhuRequestId();
            // payChannelRequestDO.setResponse();
            // payChannelRequestDO.setRequestParams();
            payChannelRequestDO.setRequestParams(JsonUtils.toJsonString(JsonUtils.toJsonString(bill99SinglePaymentDto)));
            // 发起请求
            String requestKQ = buildHttpsClient.requestKQ(bill99Header, bill99SinglePaymentDto, url, bill99AppChannelParams);
            payChannelRequestDO.setResponse(requestKQ);
            channelPayOrderContext.setPayChannelRequestDO(payChannelRequestDO);
            // 返回数据
            Bill99ResponseDto<Bill99SinglePaymentDto> bill99ResponseDto = JsonUtils.parseObject(requestKQ, new TypeReference<Bill99ResponseDto<Bill99SinglePaymentDto>>() {
            });
            log.info("快钱提交单笔代付返回结果:{}", JsonUtils.toJsonString(bill99ResponseDto));
            // 0000
            String responseCode = bill99ResponseDto.getHead().getResponseCode();

            if (!"0000".equals(responseCode)) {
                channelPayOrderContext.setProcessStatus(false);
                channelPayOrderContext.setRemark(bill99ResponseDto.getHead().getResponseTextMessage());
            }
            else {
                Bill99SinglePaymentDto responseBody = bill99ResponseDto.getResponseBody();
                if (!"0000".equals(responseBody.getBizResponseCode())) {
                    log.info("快钱提交单笔代付 返回失败:{}", responseBody.getBizResponseCode());
                    channelPayOrderContext.setProcessStatus(false);
                }else{
                    log.info("快钱提交单笔代付 返回成功:{}", responseBody.getBizResponseCode());
                    channelPayOrderContext.setProcessStatus(true);
                }
                channelPayOrderContext.setRemark(responseBody.getBizResponseMessage());
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark(e.getMessage());
        }

    }

    @Override
    public void queryChannelAccount(ChannelPaymentAccountContext channelPayOrderContext) {
        MerchantAppChannelDO merchantAppChannelDO = channelPayOrderContext.getMerchantAppChannelDO();
        log.info("快钱查询账号余额 detailPaymentId:{}", merchantAppChannelDO.getCode());
        String appConfigJson = merchantAppChannelDO.getAppConfigJson();
        if (!StringUtils.hasText(appConfigJson)) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数未配置");
            return;
        }
        Bill99AppChannelParams bill99AppChannelParams = null;
        try {
            bill99AppChannelParams = JsonUtils.parseObject(appConfigJson, Bill99AppChannelParams.class);
            bill99AppChannelParams(bill99AppChannelParams);
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数配置格式错误");
        }

        Bill99Header bill99Header = new Bill99Header();
        bill99Header.setMessageType("M0001");
        bill99Header.setMemberCode(bill99AppChannelParams.getMemberCode());
        bill99Header.setExternalRefNumber(System.currentTimeMillis() + "");
        Map<String, Object> params = new HashMap<>();
        params.put("targetMemberCode", bill99AppChannelParams.getMemberCode());
        params.put("acctTypeList", channelPayOrderContext.getAcctTypeList());
        String url = url(channelPayOrderContext.isTest());
        try {
            // 发起请求
            String requestKQ = buildHttpsClient.requestKQ(bill99Header, params, url, bill99AppChannelParams);
            Bill99ResponseDto<Bill99AcctBalanceList> bill99ResponseDto = JsonUtils.parseObject(requestKQ, new TypeReference<Bill99ResponseDto<Bill99AcctBalanceList>>() {
            });
            log.info("快钱查询账号余额返回结果:{}", JsonUtils.toJsonString(bill99ResponseDto));
            // 0000
            String responseCode = bill99ResponseDto.getHead().getResponseCode();
            if (!"0000".equals(responseCode)) {
                channelPayOrderContext.setProcessStatus(false);
                channelPayOrderContext.setRemark(bill99ResponseDto.getHead().getResponseTextMessage());
            }
            else {
                Bill99AcctBalanceList acctBalanceList = bill99ResponseDto.getResponseBody();
                List<Bill99AcctBalance> acctBalances = acctBalanceList.getAcctBalanceList();
                if (CollectionUtils.isEmpty(acctBalances)) {
                    return;
                }
                List<MerchantAcctBalanceDto> merchantAcctBalances = new ArrayList<>();
                acctBalances.stream().forEach(acctBalance -> {
                    MerchantAcctBalanceDto merchantAcctBalanceDto = new MerchantAcctBalanceDto();
                    merchantAcctBalanceDto.setBalance(MerchantUtils.fenToYuan(acctBalance.getBalance()));
                    merchantAcctBalanceDto.setAcctType(acctBalance.getAcctType());
                    merchantAcctBalances.add(merchantAcctBalanceDto);
                });
                channelPayOrderContext.setMerchantAcctBalances(merchantAcctBalances);
            }
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark(e.getMessage());
        }
    }

    @Override
    public void queryChannelPayment(ChannelPaymentContext channelPayOrderContext) {
        log.info("快钱查询单笔代付 detailPaymentId:{}", channelPayOrderContext.getMerchantPaymentDetailDO().getDetailPaymentId());
        MerchantAppChannelDO merchantAppChannelDO = channelPayOrderContext.getMerchantAppChannelDO();
        MerchantPaymentDetailDO merchantPaymentDetailDO = channelPayOrderContext.getMerchantPaymentDetailDO();
        String appConfigJson = merchantAppChannelDO.getAppConfigJson();
        if (!StringUtils.hasText(appConfigJson)) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数未配置");
            return;
        }
        Bill99AppChannelParams bill99AppChannelParams = null;
        try {
            bill99AppChannelParams = JsonUtils.parseObject(appConfigJson, Bill99AppChannelParams.class);
            bill99AppChannelParams(bill99AppChannelParams);
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数配置格式错误");
        }

        Bill99Header bill99Header = new Bill99Header();
        bill99Header.setMessageType("C1018");
        bill99Header.setMemberCode(bill99AppChannelParams.getMemberCode());
        bill99Header.setExternalRefNumber(merchantPaymentDetailDO.getDetailPaymentId());
        Bill99SinglePaymentQueryDto bill99SinglePaymentDto = new Bill99SinglePaymentQueryDto();
        bill99SinglePaymentDto.setPageNo(1);
        bill99SinglePaymentDto.setPageSize(1);
        bill99SinglePaymentDto.setExternalRefNumber(merchantPaymentDetailDO.getDetailPaymentId());
        String url = url(channelPayOrderContext.isTest());
        try {
            // 发起请求
            String requestKQ = buildHttpsClient.requestKQ(bill99Header, bill99SinglePaymentDto, url, bill99AppChannelParams);
            // 返回数据
            Bill99ResponseDto<Bill99SinglePaymentQueryResponseDto> bill99ResponseDto = JsonUtils.parseObject(requestKQ,
                    new TypeReference<Bill99ResponseDto<Bill99SinglePaymentQueryResponseDto>>() {
                    });
            log.info("快钱查询交易状态返回结果:{}", JsonUtils.toJsonString(bill99ResponseDto));
            // 0000
            String responseCode = bill99ResponseDto.getHead().getResponseCode();
            if (!"0000".equals(responseCode)) {
                channelPayOrderContext.setProcessStatus(false);
                channelPayOrderContext.setRemark(bill99ResponseDto.getHead().getResponseTextMessage());
            }
            else {
                Bill99SinglePaymentQueryResponseDto responseBody = bill99ResponseDto.getResponseBody();
                channelPayOrderContext.setRemark(responseBody.getBizResponseMessage());
                if (!"0000".equals(responseBody.getBizResponseCode())) {
                    MerchantPaymentDetailDO updateTransferOrderDO = new MerchantPaymentDetailDO();
                    if (!CollectionUtils.isEmpty(responseBody.getDetailedList())) {
                        Bill99SinglePaymentQueryResponseDto.DetailedListBean detailedListBean = responseBody.getDetailedList().get(0);
                        // S-交易成功; F-交易失败;P-交易处理中; R-交易退票
                        switch (detailedListBean.getTxnStatus()) {
                            case "S":
                                updateTransferOrderDO.setStatus(MerchantEnum.PROCESS_STATUS.SUCCESS.getCode());
                                break;
                            case "F":
                                updateTransferOrderDO.setStatus(MerchantEnum.PROCESS_STATUS.FAIL.getCode());
                                updateTransferOrderDO.setRemark(detailedListBean.getFailMessage());
                                break;
                            case "R":
                                updateTransferOrderDO.setStatus(MerchantEnum.PROCESS_STATUS.REFUND.getCode());
                                updateTransferOrderDO.setRemark(detailedListBean.getFailMessage());
                                break;
                            case "P":
                                updateTransferOrderDO.setStatus(MerchantEnum.PROCESS_STATUS.DOING.getCode());
                                break;
                        }
                    }
                    else {
                        log.info("快钱查询单笔代付返回没有详情 直接失败 detailPaymentId:{}", channelPayOrderContext.getMerchantPaymentDetailDO().getDetailPaymentId());
                        updateTransferOrderDO.setStatus(MerchantEnum.PROCESS_STATUS.FAIL.getCode());
                        if (!StringUtils.hasText(merchantPaymentDetailDO.getRemark())) {
                            channelPayOrderContext.setRemark("快钱查询单笔代付返回没有详情 直接失败");
                        }
                    }
                    channelPayOrderContext.setUpdateMerchantPaymentDetailDO(updateTransferOrderDO);
                }
            }
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark(e.getMessage());
        }
    }

    @Override
    public void queryChannelPaymentProof(ChannelPaymentContext channelPayOrderContext) {
        MerchantAppChannelDO merchantAppChannelDO = channelPayOrderContext.getMerchantAppChannelDO();
        log.info("快钱查询付款凭证 detailPaymentId:{}", merchantAppChannelDO.getCode());
        String appConfigJson = merchantAppChannelDO.getAppConfigJson();
        if (!StringUtils.hasText(appConfigJson)) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数未配置");
            return;
        }
        Bill99AppChannelParams bill99AppChannelParams = null;
        try {
            bill99AppChannelParams = JsonUtils.parseObject(appConfigJson, Bill99AppChannelParams.class);
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark("通道参数配置格式错误");
        }
        MerchantPaymentDetailDO merchantPaymentDetailDO = channelPayOrderContext.getMerchantPaymentDetailDO();

        Bill99Header bill99Header = new Bill99Header();
        bill99Header.setMessageType("C1022");
        bill99Header.setMemberCode(bill99AppChannelParams.getMemberCode());
        Map<String, Object> params = new HashMap<>();
        params.put("externalRefNumber", merchantPaymentDetailDO.getDetailPaymentId());
        String url = url(channelPayOrderContext.isTest());
        try {
            // 发起请求
            String requestKQ = buildHttpsClient.requestKQ(bill99Header, params, url, bill99AppChannelParams);
            Bill99ResponseDto<Bill99PaymentProof> bill99ResponseDto = JsonUtils.parseObject(requestKQ, new TypeReference<Bill99ResponseDto<Bill99PaymentProof>>() {
            });
            // 0000
            String responseCode = bill99ResponseDto.getHead().getResponseCode();
            if (!"0000".equals(responseCode)) {
                channelPayOrderContext.setProcessStatus(false);
                channelPayOrderContext.setRemark(bill99ResponseDto.getHead().getResponseTextMessage());
            }
            else {
                Bill99PaymentProof responseBody = bill99ResponseDto.getResponseBody();
                channelPayOrderContext.setVoucherFileStream(responseBody.getVoucherFileStream());
            }
        }
        catch (Exception e) {
            channelPayOrderContext.setProcessStatus(false);
            channelPayOrderContext.setRemark(e.getMessage());
        }
    }

    @Override
    public ChannelPaymentCallBackDto parseCallBackText(ChannelPaymentCallBackContext channelPaymentCallBackContext, HttpServletRequest servletRequest) {
        ChannelPaymentCallBackDto channelPaymentCallBackDto = new ChannelPaymentCallBackDto();
        MerchantAppChannelDO merchantAppChannelDO = channelPaymentCallBackContext.getMerchantAppChannelDO();
        String body = HttpRequestUtil.requestBodyParams(servletRequest);
        String appConfigJson = merchantAppChannelDO.getAppConfigJson();
        if (!StringUtils.hasText(appConfigJson)) {
            channelPaymentCallBackDto.setProcessStatus(false);
            channelPaymentCallBackDto.setRemark("通道参数未配置");
            return channelPaymentCallBackDto;
        }
        Bill99AppChannelParams bill99AppChannelParams = null;
        try {
            bill99AppChannelParams = JsonUtils.parseObject(appConfigJson, Bill99AppChannelParams.class);
            bill99AppChannelParams(bill99AppChannelParams);
        }
        catch (Exception e) {
            channelPaymentCallBackDto.setProcessStatus(false);
            channelPaymentCallBackDto.setRemark("通道参数配置格式错误");
            return null;
        }
        try {
            String requestKQ = buildHttpsClient.unSeal(bill99AppChannelParams, body);
            Bill99ResponseDto<Bill99SinglePaymentDto> bill99ResponseDto = JsonUtils.parseObject(requestKQ, new TypeReference<Bill99ResponseDto<Bill99SinglePaymentDto>>() {
            });
            // 0000
            Bill99ResponseDto.HeadBean head = bill99ResponseDto.getHead();
            MerchantPaymentDetailDO merchantPaymentDetailDO = new MerchantPaymentDetailDO();
            merchantPaymentDetailDO.setDetailPaymentId(head.getExternalRefNumber());
            channelPaymentCallBackDto.setMerchantPaymentDetailDO(merchantPaymentDetailDO);
            channelPaymentCallBackDto.setRequestParams(JsonUtils.toJsonString(bill99ResponseDto));
            Bill99SinglePaymentDto responseBody = bill99ResponseDto.getResponseBody();
            if ("0000".equals(responseBody.getBizResponseCode())) {
                // S-交易成功; F-交易失败;P-交易处理中; R-交易退票
                switch (responseBody.getTxnStatus()) {
                    case "S":
                        merchantPaymentDetailDO.setStatus(MerchantEnum.PROCESS_STATUS.SUCCESS.getCode());
                        break;
                    case "F":
                        merchantPaymentDetailDO.setStatus(MerchantEnum.PROCESS_STATUS.FAIL.getCode());
                        break;
                    case "R":
                        merchantPaymentDetailDO.setStatus(MerchantEnum.PROCESS_STATUS.REFUND.getCode());
                        break;
                }
                if (StringUtils.hasText(responseBody.getEndDate())) {
                    try {
                        merchantPaymentDetailDO.setSuccessTime(DateUtils.shanghaiDate(responseBody.getEndDate()));
                    }
                    catch (Exception e) {
                        log.error("快钱付款回调返回 时间格式化错误 dateTime:{},message:{}", responseBody.getEndDate(), e.getMessage());
                    }
                }
                merchantPaymentDetailDO.setThirdPaymentId(responseBody.getTxnNo());
                if (responseBody.getDealCharge() != null) {
                    merchantPaymentDetailDO.setThirdDealAmount(MerchantUtils.fenToYuan(responseBody.getDealCharge()));
                }
            }
            return channelPaymentCallBackDto;
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("快钱密文解密失败 message:{}", e.getMessage());
            return null;
        }
    }

    @Override
    public ChannelPaymentCallBackDto parseCallBackTextFix(HttpServletRequest accessCallBody) {
        // 快钱 参数解析方法为parseCallBackTextF
        return null;
    }

    @Override
    public String processCallBack(MerchantAppChannelDO merchantAppChannelDO, CommonResult commonResult) {
        Map<String, Object> callParams = new HashMap<>();
        callParams.put("isReceived", "1");
        callParams.put("messageType", "C1011");
        callParams.put("origMessageType", "C1019");
        String appConfigJson = merchantAppChannelDO.getAppConfigJson();
        if (!StringUtils.hasText(appConfigJson)) {
            log.error("通道参数未配置");
            return null;
        }
        Bill99AppChannelParams bill99AppChannelParams = null;
        try {
            bill99AppChannelParams = JsonUtils.parseObject(appConfigJson, Bill99AppChannelParams.class);
        }
        catch (Exception e) {
            log.error("通道参数配置格式错误");
            return null;
        }
        try {
            Bill99Header bill99Header = new Bill99Header();
            bill99Header.setMessageType(callParams.get("messageType").toString());
            bill99Header.setOrigMessageType(callParams.get("origMessageType").toString());
            bill99Header.setMemberCode(bill99AppChannelParams.getMemberCode());
            bill99Header.setExternalRefNumber(System.currentTimeMillis() + "");
            callParams.remove("messageType");
            callParams.remove("origMessageType");
            return buildHttpsClient.seal(bill99Header, callParams, bill99AppChannelParams);
        }
        catch (Exception e) {
            log.error("块钱回调返回参数加密异常:{}", e.getMessage());
            return null;
        }
    }

    @Override
    public Boolean verify(ProviderChannelConfigDO providerChannelConfigDO, MerchantAppChannelDO merchantAppChannelDO, String accessCallBody) {
        // 快钱 回调地址包含通道信息 数据解析时已经验签
        return null;
    }

    @Override
    public void notifyChannel(ChannelPaymentContext channelPaymentContext) {

    }

    @Override
    public void submitChannelSingleRecharge(ChannelPaymentContext channelPaymentContext) {

    }

    @Override
    public void notifyProofGenerate(ChannelPaymentContext channelPaymentContext) {

    }

    Bill99SinglePaymentDto buildPaymentDto(MerchantPaymentDetailDO merchantPaymentDetailDO, String notifyUrl) {
        Bill99SinglePaymentDto bill99SinglePaymentDto = new Bill99SinglePaymentDto();
        bill99SinglePaymentDto.setAmount(MerchantUtils.YuanToFen(merchantPaymentDetailDO.getPayAmount()));
        bill99SinglePaymentDto.setCardHolderName(merchantPaymentDetailDO.getName());
        bill99SinglePaymentDto.setBankName(merchantPaymentDetailDO.getBankName());
        bill99SinglePaymentDto.setPan(merchantPaymentDetailDO.getCardNo());
        bill99SinglePaymentDto.setBranchName(merchantPaymentDetailDO.getBranchName());
        if (StringUtils.hasText(merchantPaymentDetailDO.getProvinceName())) {
            bill99SinglePaymentDto.setProvince(merchantPaymentDetailDO.getProvinceName().replace("省", ""));
        }
        if (StringUtils.hasText(merchantPaymentDetailDO.getCityName())) {
            bill99SinglePaymentDto.setCity(merchantPaymentDetailDO.getCityName().replace("市", ""));
        }
        if (CommonEnum.YES_NO_TYPE.NO.getCode().equals(merchantPaymentDetailDO.getFeePayer())) {
            bill99SinglePaymentDto.setFeePayer("0");
        }
        else {
            bill99SinglePaymentDto.setFeePayer("1");
        }
        bill99SinglePaymentDto.setPhoneNo(merchantPaymentDetailDO.getCardPhone());
        bill99SinglePaymentDto.setReMark(merchantPaymentDetailDO.getRemark());
        bill99SinglePaymentDto.setNotifyUrl(notifyUrl);
        return bill99SinglePaymentDto;
    }

    String url(boolean test) {
        String url = "https://sandbox.99bill.com:7445/umgw/common/distribute.html";
        if (!test) {
            url = "https://umgw.99bill.com/umgw/common/distribute.html";
        }
        return url;
    }

    public void bill99AppChannelParams(Bill99AppChannelParams bill99AppChannelParams) {
        if (active.equals("prod")) {
            return;
        }
        log.info("快钱非prod 环境,更新证书信息");
        bill99AppChannelParams.setPublicPath(bill99AppChannelParams.getPublicPath().replace("www/wwwroot/pay/uploads", "E:/work/local_file"));
        bill99AppChannelParams.setPrivatePath(bill99AppChannelParams.getPrivatePath().replace("www/wwwroot/pay/uploads", "E:/work/local_file"));
    }
}
